<?php
    include("./dbconn.php");

    //接收数据
    $user = $_GET["user"];
    $pw = $_GET["pw"];

    //查询用户名是否重复
    $sql = "select * from vip where user='$user'";

    $result = $conn->query($sql);

    if ($result->num_rows > 0){
        //用户名重复
        $data["code"] = 1;
    }else{
        //不重复
        $sql = "insert into vip (user,pw) values ('$user','$pw')";
        
        if ($conn->query($sql) === TRUE){
            // 注册成功
            $data['code'] = 2;
            $data['msg']='注册成功';
        }else{
            // 注册失败
            // {code: 0}
            $data["code"] = 0;
        }
    }
    echo json_encode($data);
?>